Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fall back to default syndicate when site has no syndicate link
Fixes #1154
What changed
One line in
syndicate_from_request()inbackend/lib/syndicate.py. The anonymous-request fallback was:If the site isn't linked to any syndicate, that returns None and the context processor crashes on
.name, which 500s every anonymous page on that host (details in the issue). Now it falls back to the default syndicate (first by id) instead - the same one theadd_site_to_default_syndicatesignal picks when it links newly created sites. So new sites and existing unlinked ones end up treated the same way.Why
I hit this while sorting out #1152 on my own server. Keeping exactly one site linked to the syndicate is what makes media URLs come out with a predictable host, but before this fix, the unlinked hosts couldn't serve a login page anymore. This lets both work at once. It's a small defensive fix, nothing more.
How I tested it
syndicate_from_request()inbackend/lib/tests.py: a linked site still resolves its own syndicate, an unlinked one resolves the default instead of None.backend/app/tests.pythat the login page over an unlinked site's host renders 200 instead of crashing. That test class overridesSTATICFILES_STORAGEto the plain storage, since the manifest storage wants acollectstaticthat hasn't run in the test container.docker compose -f docker-compose.yml -f docker-compose-dev.yml run --rm web python manage.py test). The 3 new tests pass. The suite also shows 33 errors inHeaterTrackerTestCasethat are identical on a clean master checkout - looks like a test isolation thing (it's a TransactionTestCase, and the post-test flush deletes the default syndicate thatUser.syndicatedefaults to). Not caused or fixed here.Notes
No migrations, no config changes. Only requests that used to crash behave differently - anything that resolved a syndicate before resolves the same one now.
In case it comes up: this doesn't remove a way to disable a host. Unlinking never actually blocked access (logged-in users kept working the whole time), and deleting the Site record just gets you a different 500. If you want to stop serving a host, that's a reverse proxy or DNS job.